package fuckTest.builder;

public class Bank {

    private Integer id;
    private String bankCode;
    private String bankName;

    public Bank() {
    }

    private Bank(Builder builder) {
        id = builder.id;
        bankCode = builder.bankCode;
        bankName = builder.bankName;
    }

    public static Builder newBuilder(){
        return new Builder();
    }

    public static Builder newBuilder(Bank bank){
        return new Builder()
                .id(bank.id)
                .bankCode(bank.bankCode)
                .bankName(bank.bankName);
    }


    public static final class Builder {

        private Integer id;
        private String bankCode;
        private String bankName;

        public Builder() {
        }

        public Builder id(Integer val) {
            id = val;
            return this;
        }

        public Builder bankCode(String val) {
            bankCode = val;
            return this;
        }

        public Builder bankName(String val) {
            bankName = val;
            return this;
        }

        public Bank build() {
            return new Bank(this);
        }
    }


    public static void main(String[] args) {
        Bank bank = Bank.newBuilder()
                .id(123)
                .bankCode("ayk")
                .bankName("中国银行")
                .build();

        bank = Bank.newBuilder(bank)
                .bankName("中国工商银行")
                .build();
    }
}
